//
//  main.m
//  Day9test
//
//  Created by dllo on 16/5/16.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MyFunction.h"
void change(int *a ,int *b);
void changeThree (int *a, int *b, int *c);

int main(int argc, const char * argv[]) {
#if 0
    int age1 = 20, age2 = 24;
    int *p = &age1;
    p = &age2;
    *p = 99;
    
    printf("%d\n", age2);
    
#endif
    
    
#if 0
    
    int age1 = 88, age2 = 66;
    int *p = &age1;
    p = &age2;
    *p = 199;
    
    
    
#endif
    
    
#if 0
    
    int a = 10;
    int b = 20;
    
    change(&a, &b);
    printf("%d,",a);
    
    
#endif
    
    
#if 0
    
    int a = 10;
    int b = 20;
    int c = 30;
    
    
    
    changeThree(&a, &b, &c);
    
    printf("%d,%d,%d",a,b,c);
    

    
#endif
    
    
#if 0
    int *a = NULL;
    char *b = NULL;
    float *c = NULL;
    double *d = NULL;
    
    printf("%lu,%lu,%lu,%lu",sizeof(a),sizeof(b),sizeof(c),sizeof(d));
    
    // 无论什么数据类型的指针,在64为的操作系统上,所有指针都是8个字节
    // 指针为什么要分类型:因为系统在取指针所保存的地址对应的数据时,可以知道要取多少字节的数据
    
#endif
    
    
#if 0
    int a = 5;
    int b = 6;
    int c = 7;
    int d = 8;
    
    int *p = NULL;
//    p = &b;
//    p++;
//    
//    printf("%d\n",*p);
    
    printf("a = %p  b = %p c = %p d =%p",&a,&b,&c,&d);
    
    //指针的加1并不是真正的加1,而是加上指针数据类型在内存中所占的字节数.例如 :int *p = 1;  p++加的就是4.
    
#endif
    
    
    
#if 0
    
    int a[5] = {1, 2, 4, 5, 6};
    printf("a = %p\n", a);
    printf("a = %p\n", &a[0]);
    //数组名就是数组的地址
    //数组首元素的地址就是数组的地址
    //a == &a[0]
    
    // p[0] == *p  p[1] == *(p + 1)  语法糖
    
    int *p = a;
    
    for (int i = 0;i < 5; i++) {
        printf("%d",p[i]);
        printf("%d",*(p + i));
        
    }
    
    
#endif
    
#if 0
    short a[4] = {532, 2 , 3, 5};
    int *p = a;
    char *q = a;
    
    printf("%d",p[1]);
    
    // 指针变量的数据类型应该和数组元素的数据类型一致.
    
    
    
#endif
    
    
#if 0
    char string[] = "lanou3g";
    char *p = string;
    //操作字符
    *(p + 1) = 'A';
    //操作字符串
    printf("string: %s\n", p);
    
    
    
#endif
    
    
#if 0
    int a[5] ={1, 2, 3, 4, 5};
    int *p = a;
    for (int i = 0;i < 5; i++) {
        printf("%d", p[i]);
    }
    for (int i = 0; i < 5; i++) {
        printf("%d", *(p + i));
    }
    
    
    
    
    
#endif
    
#if 0
    int a[5] = {5, 4, 3, 2, 1};
    
    sort2(a, 5);
    
    
    for (int i = 0;i < 5; i++) {
        printf("%d,",a[i]);
    }
#endif
    
    
#if 1
    
    char a[5] = "abcde"; //数组保存字符串:保存在栈区,相同内容的字符串会连续的开辟存储空间,数组保存的字符串可以修改
    a[0] = 'n';
    printf("a = %p\n", a);
    
    
    
    
    char *b = "aBcde"; //指针保存字符串:保存在常量区,相同内容的字符串,不会重复的开辟存储空间,指针保存的字符串在常量区不可修改.
    printf("b = %p\n", b);
    
    char c[5] = "abcde";
    printf("c = %p\n", c);
    
    char *d = "abcde";
    printf("d = %p\n", d);
    
    
    
#endif
    
    
    
    return 0;
}

void change(int *a ,int *b) {
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}



void changeThree (int *p1, int *p2, int *p3) {
  
    int sum = *p1 + *p2 + *p3;
    *p2 = *p1 - *p2 - *p3;
    *p3 = sum / 3;
    *p1 = sum;
    
    
    
//    printf("和为:%d\n差为:%d\n平均值为:%d\n", sum, cha, avg);
    
    
    
}


